<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('【请填写功能名称】列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>项目名称：</p>
                            <input type="text" name="onlineExperimentName"/>
                        </li>
                        <li>
                            <p>用户名：</p>
                            <div class="col-sm-8">
                                <input name="userName" class="form-control" type="text">
                            </div>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <!--<div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:onlineExperimentOrder:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:onlineExperimentOrder:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:onlineExperimentOrder:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:onlineExperimentOrder:export">
                <i class="fa fa-download"></i> 导出
             </a>
        </div>-->
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:onlineExperimentOrder2:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:onlineExperimentOrder2:remove')}]];
    var prefix = ctx + "system/OnlineExperimentTend";

    $(function() {
        var options = {
            url: prefix + "/orderList",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/approve/{data}",
            modalName: "实验项目内容",
            columns: [{
                checkbox: true
            },
                {
                    field : 'onlineExperimentId',
                    title : '项目编号',
                    visible: false
                },
                {
                    field : 'onlineExperimentName',
                    title : '项目名称'
                },
                {
                    field : 'userName',
                    title : '预约人'
                },
                {
                    field : 'beginTime',
                    title : '开始时间'
                },
                {
                    field : 'endTime',
                    title : '结束时间'
                },
                {
                    field : 'status',
                    title : '预约状态',
                    formatter: function (value, row, index) {
                         if(value==2){
                             return "<a class='btn btn-primary btn-xs'  href=\"javascript:void(0)\">待批准</a>"
                         }else if(value==1){
                             return "<a class='btn btn-success btn-xs'  href=\"javascript:void(0)\">已批准</a>"
                         }else{
                             return "<a class='btn btn-danger btn-xs'  href=\"javascript:void(0)\">拒绝</a>"
                         }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status==1){
                            actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)"  disabled="disabled" title="已批准，不可再次点击"><i class="fa fa-edit"></i>审批</a> ');
                        }else{
                            actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="approve(\'' + row.onlineExperimentId + ','+ row.userId +',1'+'\')"><i class="fa fa-edit"></i>审批</a> ');
                        }
                        actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="approve(\'' + row.onlineExperimentId + ','+ row.userId +',3'+'\')"><i class="fa fa-remove"></i>拒绝</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /**
     * 执行审批操作
     * @param value  包括项目id,申请人id,以及审批状态
     */
    function approve(value) {
        //$.modal.confirm("确定要执行此操作？",approve1(value));
        $.modal.confirm("确定要执行此操作？", function() {
            $.ajax({
                type : 'post',
                url : prefix + '/approve',
                data : {'data' : value},
                dataType : 'json',
                success : function (data) {
                    if(data.code==0){
                        $.modal.msgReload("操作成功，可在项目教学中查看具体布置实验信息。",'success');
                    }else if(code==500){
                        $.modal.msgReload("操作失败，可在项目教学中查看具体布置实验信息。",'error');
                    }
                }
            })
        })
    }
</script>
</body>
</html>